//
//  LoginService.m
//  xiaomaocuoyi
//
//  Created by 蔡舟 on 15/12/14.
//  Copyright © 2015年 com.xiaomaocuoyi. All rights reserved.
//

#import "LoginService.h"

@implementation LoginService
{
    AFHTTPRequestOperationManager *manager;
}

-(instancetype) init{
    self = [super init];
    manager = [[AFHTTPRequestOperationManager alloc] init];
    AFJSONResponseSerializer *jsonReponseSerializer = [AFJSONResponseSerializer serializer];
    jsonReponseSerializer.acceptableContentTypes = nil;
    manager.responseSerializer = jsonReponseSerializer;
    
    return self;
}

-(void)getValidateNum:(NSMutableDictionary *)dic andView:(UIView *)view{
    NSString *url = [ip_and_port stringByAppendingString:@"userAction!sendPhoneValid.action"];
    NSLog(@"url:%@\n dic:%@",url,dic);
    [manager POST:url parameters:dic success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSMutableDictionary *dicRootData = responseObject;
        NSLog(@"dicRootData:%@",dicRootData[@"flag"]);
        NSNumber *flag = dicRootData[@"flag"];
        if ([flag intValue]==1) {
            [self.delegate getValidateNumSuccess];
        }else{
            [self.delegate getValidateNumFail];
        }
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"获取验证码error:%@",error);
    }];
}

-(void)getLoginUser:(NSMutableDictionary *)dic andView:(UIView *)view{
    NSString *url = [ip_and_port stringByAppendingString:@"userAction!iosLogin.action"];
    NSLog(@"url:%@\n dic:%@",url,dic);
    [manager POST:url parameters:dic success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSMutableDictionary *dicRootData = responseObject;
        NSLog(@"dicRootData:%@,%@",dicRootData,responseObject);
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"登录error:%@",error);
    }];
}

@end
